#獲取IIS網站的域名
function Get-IISWebSiteUrl([string]$name)
{
    [string[]] $site = @()
    (Get-Website $name).bindings.Collection | foreach {
        $bindingTokens = $_.bindingInformation -split ':'
        $siteHost = ''
        $port = ''
        $protocol = $_.protocol

        if($bindingTokens[2] -ne '')
        {
            $siteHost = $bindingTokens[2]
        }elseif ($bindingTokens[0] -ne '*') {
            $siteHost = $bindingTokens[0]
        }else {
            # $siteHost = [net.dns]::GetHostAddresses('') |
            # where { $_.AddressFamily -eq 'InterNetwork'} |
            # select -ExpandProperty IPAddressToString -First 1
            $siteHost = 'localhost'
        }

        if($bindingTokens[1] -eq '80') { $port = '' }
        else { $port = ':' + $bindingTokens[1] }

        $site = $site + ('{0}://{1}{2}' -f $protocol,$siteHost,$port)
    }
    $site
}

#獲取當前時間
function Get-CurrentDate()
{
    $date = Get-Date -Format 'yyyy/MM/dd HH:mm:ss fff'
    'DateTime: ' + $date
}

#輸出日誌格式
function Get-WriteLogFormat([string]$content)
{
    $log = '********* ' + $content + ' ********* ' + (Get-CurrentDate)
    $Global:logInfo =  $Global:logInfo + $log
    Write-Host $log
}

#輸出日誌  可以為''
function Get-WriteLog([string]$content)
{
    if(($content -ne $null))
    {
        $log = $content 
        $Global:logInfo =  $Global:logInfo + $log
        Write-Host $log
    }
}

#輸出日誌
function Get-WriteLogArr([string[]]$content)
{
    if(($content -ne $null) -and ($content.count -gt 0))
    {
        foreach($log in $content)
        {
            $Global:logInfo =  $Global:logInfo + $log
            Write-Host $log
        }
    }
}

#輸出文件夾所有的文件及子文件夾下的文件
function Get-AllFile([string]$dir)
{
    Get-ChildItem $dir -recurse | ForEach-Object -Process{
        if($_.psiscontainer -eq $false)
        {
            $_.fullname
        }
    }
}